package helpers

object EnumLike {

  trait Value extends Any {

    def self: String

    override def toString: String = self

    def in(others: Any*): Boolean = others.map(_ == this).reduce(_ || _)
  }

  trait Definition[T <: Value] extends ClassNameAsCanonicalName {

    def values: Seq[T]

    def Unknown: T

    def withNameOpt(name: String): Option[T] = values.find(_.self == name)

    def withName(name: String): T = withNameOpt(name).getOrElse(Unknown)

    def hasName(name: String): Boolean = values.exists(_.self == name)

    implicit def self: EnumLike.Definition[T]
  }

}
